﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Campaign_Manager
{
    public partial class frmSettlement : Form
    {
        private Settlement settle;

        public frmSettlement(Settlement Settle)
        {
            InitializeComponent();
            settle = Settle;
            boxAlignment.SelectedIndex = 1;
            boxGovernment.SelectedIndex = 0;
            boxType.SelectedIndex = 0;
            loadValues();
        }

        private void loadValues()
        {
            txtCorruption.Text = settle.getCorruption().ToString();
            txtCrime.Text = settle.getCrime().ToString();
            txtEconomy.Text = settle.getEconomy().ToString();
            txtLaw.Text = settle.getLaw().ToString();
            txtLore.Text = settle.getLore().ToString();
            txtSociety.Text = settle.getSociety().ToString();
            txtBaseValue.Text = settle.getBaseValue().ToString();
            txtPurchaseValue.Text = settle.getPurchaseLimit().ToString();
            txtCasterLevel.Text = settle.getSpellcasterLevel().ToString();
            txtDanger.Text = settle.getDangerLevel().ToString();
            txtPopulation.Text = settle.getPopulation().ToString();
            txtMinorItems.Text = settle.getMinorItems().ToString();
            txtMediumItems.Text = settle.getMediumItems().ToString();
            txtMajorItems.Text = settle.getMajorItems().ToString();
            txtName.Text = settle.getName().ToString();
            numHuman.Value = settle.getHuman();
            numDwarf.Value = settle.getDwarf();
            numGnome.Value = settle.getGnome();
            numElf.Value = settle.getElf();
            numHalfElf.Value = settle.getHalfElf();
            numHalfling.Value = settle.getHalfling();
            numHalfOrc.Value = settle.getHalfOrc();
            numChildren.Value = settle.getChildren();
        }

        private void boxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            settle.setType(boxType.SelectedIndex);
            lblQualities.Text = "Qualities (";
            switch (boxType.SelectedIndex)
            {
                case 0:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/1):";
                    break;
                case 1:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/1):";
                    break;
                case 2:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/2):";
                    break;
                case 3:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/2):";
                    break;
                case 4:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/3):";
                    break;
                case 5:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/4):";
                    break;
                case 6:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/5):";
                    break;
                case 7:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/6):";
                    break;
            }
            loadValues();
        }

        private void boxGovernment_SelectedIndexChanged(object sender, EventArgs e)
        {
            settle.setGovernment(boxGovernment.SelectedIndex);
            loadValues();
        }

        private void boxAlignment_SelectedIndexChanged(object sender, EventArgs e)
        {
            settle.setAlignment(boxAlignment.SelectedIndex);
            loadValues();
        }

        private void checkQualities_SelectedValueChanged(object sender, EventArgs e)
        {
            if (checkQualities.CheckedIndices.Contains(0))
                settle.setAcademic(true);
            else
                settle.setAcademic(false);
            if (checkQualities.CheckedIndices.Contains(1))
                settle.setHolySite(true);
            else
                settle.setHolySite(false);
            if (checkQualities.CheckedIndices.Contains(2))
                settle.setInsular(true);
            else
                settle.setInsular(false);
            if (checkQualities.CheckedIndices.Contains(3))
                settle.setMagicallyAttuned(true);
            else
                settle.setMagicallyAttuned(false);
            if (checkQualities.CheckedIndices.Contains(4))
                settle.setNotorious(true);
            else
                settle.setNotorious(false);
            if (checkQualities.CheckedIndices.Contains(5))
                settle.setPious(true);
            else
                settle.setPious(false);
            if (checkQualities.CheckedIndices.Contains(6))
                settle.setProsperous(true);
            else
                settle.setProsperous(false);
            if (checkQualities.CheckedIndices.Contains(7))
                settle.setRaciallyIntolerant(true);
            else
                settle.setRaciallyIntolerant(false);
            if (checkQualities.CheckedIndices.Contains(8))
                settle.setRumormongeringCitizens(true);
            else
                settle.setRumormongeringCitizens(false);
            if (checkQualities.CheckedIndices.Contains(9))
                settle.setStrategicLocation(true);
            else
                settle.setStrategicLocation(false);
            if (checkQualities.CheckedIndices.Contains(10))
                settle.setSuperstitious(true);
            else
                settle.setSuperstitious(false);
            if (checkQualities.CheckedIndices.Contains(11))
                settle.setTouristAttraction(true);
            else
                settle.setTouristAttraction(false);
            lblQualities.Text = "Qualities (";
            switch (boxType.SelectedIndex)
            {
                case 0:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/1):";
                    break;
                case 1:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/1):";
                    break;
                case 2:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/2):";
                    break;
                case 3:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/2):";
                    break;
                case 4:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/3):";
                    break;
                case 5:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/4):";
                    break;
                case 6:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/5):";
                    break;
                case 7:
                    lblQualities.Text += checkQualities.CheckedIndices.Count.ToString() + "/6):";
                    break;
            }
            loadValues();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            int sum = (int)numHuman.Value + (int)numDwarf.Value + (int)numGnome.Value + (int)numElf.Value + (int)numHalfElf.Value + (int)numHalfling.Value + (int)numHalfOrc.Value;
            if (sum == 100)
            {
                settle.setName(txtName.Text);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("The diversity percentages must add up to 100%.\n(excluding the Children percentage)", "Diversity Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnRandom_Click(object sender, EventArgs e)
        {

        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            settle.setName(txtName.Text);
        }

    }
}
